user_id = auth.user.id if auth.is_logged_in() else 0
auth.user_id = user_id

db.define_table('jobs',
                Field('job_name','string'),
                Field('submitted_by',db.auth_user,default=user_id,writable=False,readable=False),
                Field('submitted_time','datetime',default=request.now,writable=False,readable=False),
                Field('job_id','string',writable=False,readable=False),
                Field('status','string',default='ready',writable=False,readable=False),
                Field('script','upload',autodelete=True),
                Field('stdout','upload',writable=False,readable=False,autodelete=True),
                Field('stderr','upload',writable=False,readable=False,autodelete=True)
)

db.jobs.script.requires=IS_NOT_EMPTY()
db.jobs.job_name.requires=IS_NOT_EMPTY()
db.jobs.status.requires=IS_IN_SET(('ready','running', 'complete'))

